package com.rpay.dao.auth;

import com.google.common.collect.Maps;
import com.rpay.model.auth.AuthDO;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.util.Map;

/**
 * Title：
 * Description
 *
 * @author fxg06 on 2018/5/5
 * @version 1.0
 */
@Repository
public class AuthDao {

    @Autowired
    @Qualifier("readSqlSession")
    private SqlSessionTemplate readSqlSession;

    @Autowired
    @Qualifier("writeSqlSession")
    private SqlSessionTemplate writeSqlSession;

    public int insert(AuthDO authDO) {
        return writeSqlSession.insert("rpay.auth.insert", authDO);
    }

    public AuthDO select(String email, String secretKey) {
        Map<String, String> map = Maps.newHashMap();
        map.put("email", email);
        map.put("secretKey", secretKey);
        return readSqlSession.selectOne("rpay.auth.select", map);
    }

    public int updateValid(Integer id) {
        return writeSqlSession.update("rpay.auth.updateValid", id);
    }
}
